import java.util.Random;

public class rm extends fk
{
  protected void a(int paramInt1, int paramInt2, byte[] paramArrayOfByte, double paramDouble1, double paramDouble2, double paramDouble3)
  {
    a(paramInt1, paramInt2, paramArrayOfByte, paramDouble1, paramDouble2, paramDouble3, 1.0F + this.b.nextFloat() * 6.0F, 0.0F, 0.0F, -1, -1, 0.5D);
  }

  protected void a(int paramInt1, int paramInt2, byte[] paramArrayOfByte, double paramDouble1, double paramDouble2, double paramDouble3, float paramFloat1, float paramFloat2, float paramFloat3, int paramInt3, int paramInt4, double paramDouble4) {
    double d1 = paramInt1 * 16 + 8;
    double d2 = paramInt2 * 16 + 8;

    float f1 = 0.0F;
    float f2 = 0.0F;

    Random localRandom = new Random(this.b.nextLong());

    if (paramInt4 <= 0) {
      int i = this.a * 16 - 16;
      paramInt4 = i - localRandom.nextInt(i / 4);
    }
    int i = 0;

    if (paramInt3 == -1) {
      paramInt3 = paramInt4 / 2;
      i = 1;
    }

    int j = localRandom.nextInt(paramInt4 / 2) + paramInt4 / 4;
    int k = localRandom.nextInt(6) == 0 ? 1 : 0;

    for (; paramInt3 < paramInt4; paramInt3++) {
      double d3 = 1.5D + hy.a(paramInt3 * 3.141593F / paramInt4) * paramFloat1 * 1.0F;
      double d4 = d3 * paramDouble4;

      float f3 = hy.b(paramFloat3);
      float f4 = hy.a(paramFloat3);
      paramDouble1 += hy.b(paramFloat2) * f3;
      paramDouble2 += f4;
      paramDouble3 += hy.a(paramFloat2) * f3;

      if (k != 0)
        paramFloat3 *= 0.92F;
      else {
        paramFloat3 *= 0.7F;
      }
      paramFloat3 += f2 * 0.1F;
      paramFloat2 += f1 * 0.1F;

      f2 *= 0.9F;
      f1 *= 0.75F;
      f2 += (localRandom.nextFloat() - localRandom.nextFloat()) * localRandom.nextFloat() * 2.0F;
      f1 += (localRandom.nextFloat() - localRandom.nextFloat()) * localRandom.nextFloat() * 4.0F;

      if ((i == 0) && (paramInt3 == j) && (paramFloat1 > 1.0F)) {
        a(paramInt1, paramInt2, paramArrayOfByte, paramDouble1, paramDouble2, paramDouble3, localRandom.nextFloat() * 0.5F + 0.5F, paramFloat2 - 1.570796F, paramFloat3 / 3.0F, paramInt3, paramInt4, 1.0D);
        a(paramInt1, paramInt2, paramArrayOfByte, paramDouble1, paramDouble2, paramDouble3, localRandom.nextFloat() * 0.5F + 0.5F, paramFloat2 + 1.570796F, paramFloat3 / 3.0F, paramInt3, paramInt4, 1.0D);
        return;
      }
      if ((i == 0) && (localRandom.nextInt(4) == 0)) {
        continue;
      }
      double d5 = paramDouble1 - d1;
      double d6 = paramDouble3 - d2;
      double d7 = paramInt4 - paramInt3;
      double d8 = paramFloat1 + 2.0F + 16.0F;
      if (d5 * d5 + d6 * d6 - d7 * d7 > d8 * d8) {
        return;
      }

      if ((paramDouble1 < d1 - 16.0D - d3 * 2.0D) || (paramDouble3 < d2 - 16.0D - d3 * 2.0D) || (paramDouble1 > d1 + 16.0D + d3 * 2.0D) || (paramDouble3 > d2 + 16.0D + d3 * 2.0D))
        continue;
      int m = hy.b(paramDouble1 - d3) - paramInt1 * 16 - 1;
      int n = hy.b(paramDouble1 + d3) - paramInt1 * 16 + 1;

      int i1 = hy.b(paramDouble2 - d4) - 1;
      int i2 = hy.b(paramDouble2 + d4) + 1;

      int i3 = hy.b(paramDouble3 - d3) - paramInt2 * 16 - 1;
      int i4 = hy.b(paramDouble3 + d3) - paramInt2 * 16 + 1;

      if (m < 0) m = 0;
      if (n > 16) n = 16;

      if (i1 < 1) i1 = 1;
      if (i2 > 120) i2 = 120;

      if (i3 < 0) i3 = 0;
      if (i4 > 16) i4 = 16;

      int i5 = 0;
      int i9;
      for (int i6 = m; (i5 == 0) && (i6 < n); i6++) {
        for (int i7 = i3; (i5 == 0) && (i7 < i4); i7++) {
          for (int i8 = i2 + 1; (i5 == 0) && (i8 >= i1 - 1); i8--) {
            i9 = (i6 * 16 + i7) * 128 + i8;
            if ((i8 >= 0) && (i8 < 128)) {
              if ((paramArrayOfByte[i9] == to.A.bl) || (paramArrayOfByte[i9] == to.B.bl)) {
                i5 = 1;
              }
              if ((i8 != i1 - 1) && (i6 != m) && (i6 != n - 1) && (i7 != i3) && (i7 != i4 - 1))
                i8 = i1;
            }
          }
        }
      }
      if (i5 != 0)
        continue;
      for (int i6 = m; i6 < n; i6++) {
        double d9 = (i6 + paramInt1 * 16 + 0.5D - paramDouble1) / d3;
        for (i9 = i3; i9 < i4; i9++) {
          double d10 = (i9 + paramInt2 * 16 + 0.5D - paramDouble3) / d3;
          int i10 = (i6 * 16 + i9) * 128 + i2;
          int i11 = 0;
          if (d9 * d9 + d10 * d10 < 1.0D) {
            for (int i12 = i2 - 1; i12 >= i1; i12--) {
              double d11 = (i12 + 0.5D - paramDouble2) / d4;
              if ((d11 > -0.7D) && (d9 * d9 + d11 * d11 + d10 * d10 < 1.0D)) {
                int i13 = paramArrayOfByte[i10];
                if (i13 == to.u.bl) i11 = 1;
                if ((i13 == to.t.bl) || (i13 == to.v.bl) || (i13 == to.u.bl)) {
                  if (i12 < 10) {
                    paramArrayOfByte[i10] = (byte)to.C.bl;
                  } else {
                    paramArrayOfByte[i10] = 0;
                    if ((i11 != 0) && (paramArrayOfByte[(i10 - 1)] == to.v.bl)) paramArrayOfByte[(i10 - 1)] = (byte)to.u.bl;
                  }
                }
              }
              i10--;
            }
          }
        }
      }
      if (i != 0)
        break;
    }
  }

  protected void a(et paramet, int paramInt1, int paramInt2, int paramInt3, int paramInt4, byte[] paramArrayOfByte)
  {
    int i = this.b.nextInt(this.b.nextInt(this.b.nextInt(BiomeTerrain.getCaveFrequency() + 1) + 1) + 1);
    if (BiomeTerrain.getEvenCaveDistribution())
      i = BiomeTerrain.getCaveFrequency();
    if (this.b.nextInt(100) > BiomeTerrain.getCaveRarity()) i = 0;

    for (int j = 0; j < i; j++) {
      double d1 = paramInt1 * 16 + this.b.nextInt(16);

      double d2 = this.b.nextInt(this.b.nextInt(BiomeTerrain.getCaveMaxAltitude() - BiomeTerrain.getCaveMinAltitude()) + BiomeTerrain.getCaveMinAltitude() + 1);
      if (BiomeTerrain.getEvenCaveDistribution()) {
        d2 = this.b.nextInt(BiomeTerrain.getCaveMaxAltitude() - BiomeTerrain.getCaveMinAltitude()) + BiomeTerrain.getCaveMinAltitude();
      }
      double d3 = paramInt2 * 16 + this.b.nextInt(16);

      int k = BiomeTerrain.getCaveSystemFrequency();
      boolean l = false;
      if (this.b.nextInt(100) <= BiomeTerrain.getIndividualCaveRarity()) {
        a(paramInt3, paramInt4, paramArrayOfByte, d1, d2, d3);
        l = true;
      }

      if ((l) || (this.b.nextInt(100) <= BiomeTerrain.getCaveSystemPocketChance() - 1)) {
        k += this.b.nextInt(BiomeTerrain.getCaveSystemPocketMaxSize() - BiomeTerrain.getCaveSystemPocketMinSize()) + BiomeTerrain.getCaveSystemPocketMinSize();
      }
      for (int m = 0; m < k; m++)
      {
        float f1 = this.b.nextFloat() * 3.141593F * 2.0F;
        float f2 = (this.b.nextFloat() - 0.5F) * 2.0F / 8.0F;
        float f3 = this.b.nextFloat() * 2.0F + this.b.nextFloat();

        a(paramInt3, paramInt4, paramArrayOfByte, d1, d2, d3, f3, f1, f2, 0, 0, 1.0D);
      }
    }
  }
}